package gui.nodes;
import gui.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import utility.Record;

import business.SalleBL;


public class SalleRoot extends AbstractNode {
	
	int salleId = -1;
	
	public SalleRoot() {
		super();
	}
	
	public String getNodeName() {
		return "Salles";
	}

	public void loadPrimaryViewPane() {
	}
	
	public void loadAjouterViewPane(){
		AbstractViewPane newViewPane = new SalleUIConsulter(this, AbstractViewPane.ViewMode.AJOUT, -1);
		MainController.getInstance().setViewPane(newViewPane);
	}
	
	public JPopupMenu makePopup() {

		return new Popup();
	}
	
	private class Popup extends JPopupMenu implements ActionListener {
		JMenuItem ajouter = new JMenuItem("Ajouter");
		
		public Popup() {
			ajouter.addActionListener(this);
			add(ajouter);
		}
		
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == ajouter){
				loadAjouterViewPane();
			}
			
		}
		
	}

	@Override
	public void expandHook() {
		this.removeAllChildren();
		
		SalleBL salleBL = new SalleBL();
		
		for (Record recordSalle : salleBL.getListeSalle()) {
			SalleNode salleNode = new SalleNode(this, recordSalle);
			add(salleNode);
		}
	}

}
